package com.eurasia.assignment.controller;

import com.eurasia.assignment.service.StatisticsService;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.HashMap;
import java.util.Map;

@RestController
public class StatisticsController {

    private final StatisticsService statisticsService;

    @Autowired
    public StatisticsController(StatisticsService statisticsService) {
        this.statisticsService = statisticsService;
    }

    /**
     * 获取综合统计信息
     */
    @GetMapping("/statistics")
    public ResponseEntity<Map<String, Long>> getStatistics() {
        Map<String, Long> statistics = new HashMap<>();
        // 使用注入的statisticsService实例调用方法
        statistics.put("studentCount", statisticsService.countAllStudents());
        return ResponseEntity.ok(statistics);
    }


    /**
     * 获取学生角色的人数统计
     */
    @GetMapping("/statistics/students/count")
    public ResponseEntity<Map<String, Long>> getStudentCount() {
        Map<String, Long> response = new HashMap<>();
        response.put("studentCount", statisticsService.countStudentsWithRole());
        return ResponseEntity.ok(response);
    }
}